<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <!-- 主表单区域 -->
      <a-form :form="form" slot="detail">
        <a-row>
          <a-col :span="8" >
            <a-form-item label="签订日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择签订日期" v-decorator="['signingDate', validatorRules.signingDate]" :trigger-change="true" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="合同编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['contractCode']" disabled placeholder="请输入合同编号"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="出租方" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-popup
                v-decorator="['item', validatorRules.item]"
                :trigger-change="true"
                org-fields="item,company,deposit_park,park_number"
                dest-fields="item,company,depositPark,parkNumber"
                code="v_xy_park_accountinfo"
                @callback="popupCallback"/>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="出租方名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['company']" disabled placeholder="请输入出租方名称"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="开户银行" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['depositPark']" disabled placeholder="请输入开户银行"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="开户账户" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['parkNumber']" disabled placeholder="请输入开户账户"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="承租方编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-popup
                v-decorator="['ownerCode', validatorRules.ownerCode]"
                :trigger-change="true"
                org-fields="owner_code,owner_name,social_creditcode,id_card,contact,contact_addr,contact_tel"
                dest-fields="ownerCode,ownerName,socialCreditcode,idNumber,contractor,contactAddress,contactMethod"
                code="v_xy_park_ownerinfo"
                @callback="popupCallback"/>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="承租方" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['ownerName']" disabled placeholder="请输入承租方"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="社会信用代码" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['socialCreditcode']" disabled placeholder="请输入社会信用代码"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="身份证号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['idNumber']" disabled placeholder="请输入身份证号"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="联系人" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['contractor']" placeholder="请输入联系人"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="联系地址" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['contactAddress']" placeholder="请输入联系地址"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="联系方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['contactMethod']" placeholder="请输入联系方式"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="项目编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-popup
                v-decorator="['projectCode', validatorRules.projectCode]"
                :trigger-change="true"
                org-fields="project_code,project_name,project_address,land_number,project_landuseno"
                dest-fields="projectCode,projectName,projectAddress,landNumber,landUserpermit"
                code="v_xy_park_projectinfo"
                @callback="popupCallback"/>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['projectName']" disabled placeholder="请输入项目名称"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="项目位置" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['projectAddress']" disabled placeholder="请输入项目位置"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="土地编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['landNumber']" disabled placeholder="请输入土地编号"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="土地使用证号" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['landUserpermit']" disabled placeholder="请输入土地使用证号"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="租赁用途" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['leasePurpose', validatorRules.leasePurpose]" placeholder="请输入租赁用途"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="租赁面积（㎡）" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['leaseArea', validatorRules.leaseArea]" disabled placeholder="请输入租赁面积（㎡）"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="租金标准" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['rentStandard', validatorRules.rentStandard]" placeholder="请输入租金标准" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="租金总额（小写）" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['totalRent', validatorRules.totalRent]" @change="handleChangeTotal" placeholder="请输入租金总额（小写）" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="租金总额（大写）" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['totalRentdetail']" disabled placeholder="请输入租金总额（大写）"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="租金递增幅度" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input v-decorator="['increaseRent', validatorRules.increaseRent]" placeholder="请输入租金递增幅度"></a-input>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="缴纳方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-dict-select-tag type="list" v-decorator="['rentMethod', validatorRules.rentMethod]" :trigger-change="true" dictCode="xy_park_contract_cycle" placeholder="请选择缴纳方式"/>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="首次缴纳日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择首次缴纳日期" v-decorator="['firstPayDate', validatorRules.firstPayDate]" :trigger-change="true" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="保证金" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input-number v-decorator="['marginAmount', validatorRules.marginAmount]" placeholder="请输入保证金" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="交房时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择交房时间" v-decorator="['deliverTime', validatorRules.deliverTime]" :trigger-change="true" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="租赁开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择租赁开始时间" v-decorator="['leaseStarttime', validatorRules.leaseStarttime]" :trigger-change="true" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="租赁结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date placeholder="请选择租赁结束时间" v-decorator="['leaseEndtime', validatorRules.leaseEndtime]" :trigger-change="true" style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :span="24">
            <a-form-item label="其他约定事项" :labelCol="labelCol2" :wrapperCol="wrapperCol2">
              <a-textarea v-decorator="['contractArrange']" rows="4" placeholder="请输入其他约定事项"/>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="合同附件" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-upload v-decorator="['contractFile']" :trigger-change="true"></j-upload>
            </a-form-item>
          </a-col>
          <a-col :span="8" >
            <a-form-item label="是否三七" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-switch v-decorator="['isThreeSeven', validatorRules.isThreeSeven]" ></j-switch>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </j-form-container>
      <!-- 子表单区域 -->
    <a-tabs v-model="activeKey" @change="handleChangeTabs">
      <a-tab-pane tab="租赁合同房源信息" :key="refKeys[0]" :forceRender="true">
        <j-editable-table
          :ref="refKeys[0]"
          :loading="xyParkLeasecontractDetailTable.loading"
          :columns="xyParkLeasecontractDetailTable.columns"
          :dataSource="xyParkLeasecontractDetailTable.dataSource"
          :maxHeight="300"
          :disabled="formDisabled"
          :rowNumber="true"
          :rowSelection="true"
          :actionButton="true"
          @deleted="setServiceArea"
        >
          <template #houseCode="props">
            <j-popup
              :trigger-change="true"
              :value="props.value"
              :multi="true"
              org-fields="house_code,building,building_name,project,project_name,floor,building_area,property_area,decoration,house_type"
              dest-fields="houseCode,buildingCode,buildingName,projectCode,projectName,floor,buildingArea,propertyArea,decoration,houseType"
              code="v_xy_park_houseing"
              @callback="(row) => houseCodeCallback(row,props)"/>
          </template>
        </j-editable-table>
      </a-tab-pane>
      <a-tab-pane tab="租赁合同款项信息" :key="refKeys[1]" :forceRender="true">
        <j-editable-table
          :ref="refKeys[1]"
          :loading="xyParkLeasecontractPayinfoTable.loading"
          :columns="xyParkLeasecontractPayinfoTable.columns"
          :dataSource="xyParkLeasecontractPayinfoTable.dataSource"
          :maxHeight="300"
          :disabled="formDisabled"
          :rowNumber="true"
          :rowSelection="true"
          :actionButton="true"/>
      </a-tab-pane>
      <a-tab-pane tab="免租期" :key="refKeys[2]" :forceRender="true">
        <j-editable-table
          :ref="refKeys[2]"
          :loading="xyParkLeasecontractFreeperiodTable.loading"
          :columns="xyParkLeasecontractFreeperiodTable.columns"
          :dataSource="xyParkLeasecontractFreeperiodTable.dataSource"
          :maxHeight="300"
          :disabled="formDisabled"
          :rowNumber="true"
          :rowSelection="true"
          :actionButton="true"/>
      </a-tab-pane>
    </a-tabs>
  </a-spin>
</template>

<script>

import pick from 'lodash.pick'
// import { getAction } from '@/api/manage'
import { FormTypes, getRefPromise } from '@/utils/JEditableTableUtil'
import { JEditableTableMixin } from '@/mixins/JEditableTableMixin'
// import { validateDuplicateValue } from '@/utils/util'
import JFormContainer from '@/components/jeecg/JFormContainer'
import JDate from '@/components/jeecg/JDate'
import JUpload from '@/components/jeecg/JUpload'
import JDictSelectTag from '@/components/dict/JDictSelectTag'
import JSwitch from '@/components/jeecg/JSwitch'

export default {
  name: 'XyParkLeasecontractForm',
  mixins: [JEditableTableMixin],
  components: {
    JFormContainer,
    JDate,
    JUpload,
    JDictSelectTag,
    JSwitch
  },
  data() {
    return {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      labelCol2: {
        xs: { span: 24 },
        sm: { span: 3 }
      },
      wrapperCol2: {
        xs: { span: 24 },
        sm: { span: 20 }
      },
      // 新增时子表默认添加几行空数据
      addDefaultRowNum: 1,
      validatorRules: {
        signingDate: {
          rules: [
            { required: true, message: '请输入签订日期!' }
          ]
        },
        item: {
          rules: [
            { required: true, message: '请输入出租方!' }
          ]
        },
        ownerCode: {
          rules: [
            { required: true, message: '请输入承租方编号!' }
          ]
        },
        projectCode: {
          rules: [
            { required: true, message: '请输入项目编号!' }
          ]
        },
        leasePurpose: {
          rules: [
            { required: true, message: '请输入租赁用途!' }
          ]
        },
        leaseArea: {
          rules: [
            { required: true, message: '请输入租赁面积（㎡）!' }
          ]
        },
        rentStandard: {
          rules: [
            { required: true, message: '请输入租金标准!' },
            { pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!' }
          ]
        },
        totalRent: {
          rules: [
            { required: true, message: '请输入租金总额（小写）!' },
            { pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!' }
          ]
        },
        increaseRent: {
          rules: [
            { required: true, message: '请输入租金递增幅度!' }
          ]
        },
        rentMethod: {
          rules: [
            { required: true, message: '请输入缴纳方式!' }
          ]
        },
        firstPayDate: {
          rules: [
            { required: true, message: '请输入首次缴纳日期!' }
          ]
        },
        marginAmount: {
          rules: [
            { required: true, message: '请输入保证金!' },
            { pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的金额!' }
          ]
        },
        deliverTime: {
          rules: [
            { required: true, message: '请输入交房时间!' }
          ]
        },
        leaseStarttime: {
          rules: [
            { required: true, message: '请输入租赁开始时间!' }
          ]
        },
        leaseEndtime: {
          rules: [
            { required: true, message: '请输入租赁结束时间!' }
          ]
        },
        isThreeSeven: {
          rules: [
            { required: true, message: '请输入是否三七!' }
          ]
        }
      },
      refKeys: ['xyParkLeasecontractDetail', 'xyParkLeasecontractPayinfo', 'xyParkLeasecontractFreeperiod'],
      tableKeys: ['xyParkLeasecontractDetail', 'xyParkLeasecontractPayinfo', 'xyParkLeasecontractFreeperiod'],
      activeKey: 'xyParkLeasecontractDetail',
      // 租赁合同房源信息
      xyParkLeasecontractDetailTable: {
        loading: false,
        dataSource: [],
        columns: [
          {
            title: '房源编号',
            key: 'houseCode',
            type: FormTypes.slot,
            slotName: 'houseCode',
            // type: FormTypes.popup,
            // popupCode: 'v_xy_park_houseing',
            // destFields: 'houseCode,buildingCode,buildingName,projectCode,projectName,floor,buildingArea,propertyArea,decoration,houseType',
            // orgFields: 'house_code,building,building_name,project,project_name,floor,building_area,property_area,decoration,house_type',
            // width: '200px',
            // placeholder: '请输入${title}',
            // defaultValue: '',
            validateRules: [
              { required: true, message: '${title}不能为空' },
              { pattern: 'only', message: '${title}不能重复' }
            ]
          },
          {
            title: '楼宇编号',
            key: 'buildingCode',
            type: FormTypes.input,
            width: '200px',
            placeholder: '请输入${title}',
            disabled: true,
            defaultValue: ''
          },
          {
            title: '楼宇名称',
            key: 'buildingName',
            type: FormTypes.input,
            width: '200px',
            placeholder: '请输入${title}',
            disabled: true,
            defaultValue: ''
          },
          {
            title: '项目编号',
            key: 'projectCode',
            type: FormTypes.input,
            width: '200px',
            placeholder: '请输入${title}',
            disabled: true,
            defaultValue: ''
          },
          {
            title: '项目名称',
            key: 'projectName',
            type: FormTypes.input,
            width: '200px',
            placeholder: '请输入${title}',
            disabled: true,
            defaultValue: ''
          },
          {
            title: '楼层',
            key: 'floor',
            type: FormTypes.input,
            width: '200px',
            placeholder: '请输入${title}',
            disabled: true,
            defaultValue: ''
          },
          {
            title: '建筑面积（㎡）',
            key: 'buildingArea',
            type: FormTypes.inputNumber,
            width: '200px',
            placeholder: '请输入${title}',
            disabled: true,
            defaultValue: ''
          },
          {
            title: '产权面积（㎡）',
            key: 'propertyArea',
            type: FormTypes.inputNumber,
            width: '200px',
            placeholder: '请输入${title}',
            disabled: true,
            defaultValue: ''
          },

          {
            title: 'house_code',
            key: 'house_code',
            type: 'hidden'
          },

          {
            title: 'building_code',
            key: 'building_code',
            type: 'hidden'
          },

          {
            title: 'building_name',
            key: 'building_name',
            type: 'hidden'
          },

          {
            title: 'project_code',
            key: 'project_code',
            type: 'hidden'
          },

          {
            title: 'project_name',
            key: 'project_name',
            type: 'hidden'
          },

          {
            title: 'building_area',
            key: 'building_area',
            type: 'hidden'
          },

          {
            title: 'property_area',
            key: 'property_area',
            type: 'hidden'
          },

          {
            title: 'decoration',
            key: 'decoration',
            type: 'hidden'
          },

          {
            title: 'house_type',
            key: 'house_type',
            type: 'hidden'
          }
        ]
      },
      // 租赁合同款项信息
      xyParkLeasecontractPayinfoTable: {
        loading: false,
        dataSource: [],
        columns: [
          {
            title: '费项',
            key: 'costType',
            type: FormTypes.popup,
            popupCode: 'v_xy_park_cost_type',
            destFields: 'costType,costName',
            orgFields: 'cost_type,cost_name',
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: '',
            validateRules: [{ required: true, message: '${title}不能为空' }]
          },
          {
            title: '费项名称',
            key: 'costName',
            type: FormTypes.input,
            width: '200px',
            placeholder: '请输入${title}',
            disabled: true,
            defaultValue: ''
          },
          {
            title: '金额',
            key: 'price',
            type: FormTypes.inputNumber,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: '',
            validateRules: [{ required: true, message: '${title}不能为空' }]
          },
          {
            title: '账单开始日期',
            key: 'startDate',
            type: FormTypes.date,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: '',
            validateRules: [
              { required: true, message: '${title}不能为空' },
              { handler: this.validateDate }
            ]
          },
          {
            title: '账单结束日期',
            key: 'endDate',
            type: FormTypes.date,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: '',
            validateRules: [
              { required: true, message: '${title}不能为空' },
              { handler: this.validateDate }
            ]
          },
          {
            title: '应收日期',
            key: 'collectionDate',
            type: FormTypes.date,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: '',
            validateRules: [
              { required: true, message: '${title}不能为空' },
              { handler: this.validateCollectionDate }
            ]
          },

          {
            title: 'cost_type',
            key: 'cost_type',
            type: 'hidden'
          },

          {
            title: 'cost_name',
            key: 'cost_name',
            type: 'hidden'
          }
        ]
      },
      // 免租期
      xyParkLeasecontractFreeperiodTable: {
        loading: false,
        dataSource: [],
        columns: [
          {
            title: '开始日期',
            key: 'startDate',
            type: FormTypes.date,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: '',
            validateRules: [
              { handler: this.validateDate }
            ]
          },
          {
            title: '结束日期',
            key: 'endDate',
            type: FormTypes.date,
            width: '200px',
            placeholder: '请输入${title}',
            defaultValue: '',
            validateRules: [
              { handler: this.validateDate }
            ]
          }
        ]
      },
      url: {
        add: '/community/xyParkLeasecontract/add',
        edit: '/community/xyParkLeasecontract/edit',
        queryById: '/community/xyParkLeasecontract/queryById',
        xyParkLeasecontractDetail: {
          list: '/community/xyParkLeasecontract/queryXyParkLeasecontractDetailByMainId'
        },
        xyParkLeasecontractPayinfo: {
          list: '/community/xyParkLeasecontract/queryXyParkLeasecontractPayinfoByMainId'
        },
        xyParkLeasecontractFreeperiod: {
          list: '/community/xyParkLeasecontract/queryXyParkLeasecontractFreeperiodByMainId'
        }
      }
    }
  },
  props: {
    // 流程表单data
    formData: {
      type: Object,
      default: () => {},
      required: false
    },
    // 表单模式：false流程表单 true普通表单
    formBpm: {
      type: Boolean,
      default: false,
      required: false
    },
    // 表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  computed: {
    formDisabled() {
      if (this.formBpm === true) {
        if (this.formData.disabled === false) {
          return false
        }
        return true
      }
      return this.disabled
    }
    // showFlowSubmitButton() {
    //   if (this.formBpm === true) {
    //     if (this.formData.disabled === false) {
    //       return true
    //     }
    //   }
    //   return false
    // }
  },
  created() {
    // 如果是流程中表单，则需要加载流程表单data
    // this.showFlowData()
  },
  methods: {
    addBefore() {
      this.form.resetFields()
      this.xyParkLeasecontractDetailTable.dataSource = []
      this.xyParkLeasecontractPayinfoTable.dataSource = []
      this.xyParkLeasecontractFreeperiodTable.dataSource = []
    },
    getAllTable() {
      const values = this.tableKeys.map(key => getRefPromise(this, key))
      return Promise.all(values)
    },
    /** 调用完edit()方法之后会自动调用此方法 */
    editAfter() {
      const fieldval = pick(this.model, 'createBy', 'createTime', 'signingDate', 'contractCode', 'item', 'company', 'depositPark', 'parkNumber', 'ownerCode', 'ownerName', 'socialCreditcode', 'idNumber', 'contractor', 'contactAddress', 'contactMethod', 'projectCode', 'projectName', 'projectAddress', 'landNumber', 'landUserpermit', 'leasePurpose', 'leaseArea', 'rentStandard', 'totalRent', 'totalRentdetail', 'increaseRent', 'rentMethod', 'firstPayDate', 'marginAmount', 'deliverTime', 'leaseStarttime', 'leaseEndtime', 'contractArrange', 'contractFile', 'bpmStatus', 'isThreeSeven')
      this.$nextTick(() => {
        this.form.setFieldsValue(fieldval)
      })
      // 加载子表数据
      if (this.model.contractCode) {
        const params = { id: this.model.contractCode }
        this.requestSubTableData(this.url.xyParkLeasecontractDetail.list, params, this.xyParkLeasecontractDetailTable)
        this.requestSubTableData(this.url.xyParkLeasecontractPayinfo.list, params, this.xyParkLeasecontractPayinfoTable)
        this.requestSubTableData(this.url.xyParkLeasecontractFreeperiod.list, params, this.xyParkLeasecontractFreeperiodTable)
      }
    },
    /** 整理成formData */
    classifyIntoFormData(allValues) {
      const main = Object.assign(this.model, allValues.formValue)
      return {
        ...main, // 展开
        xyParkLeasecontractDetailList: allValues.tablesValue[0].values,
        xyParkLeasecontractPayinfoList: allValues.tablesValue[1].values,
        xyParkLeasecontractFreeperiodList: allValues.tablesValue[2].values
      }
    },
    // 渲染流程表单数据
    // showFlowData() {
    //   if (this.formBpm === true) {
    //     const params = { id: this.formData.dataId }
    //     getAction(this.url.queryById, params).then((res) => {
    //       if (res.success) {
    //         this.edit(res.result)
    //       }
    //     })
    //   }
    // },
    validateError(msg) {
      this.$message.error(msg)
    },
    popupCallback(row) {
      this.form.setFieldsValue(pick(row, 'createBy', 'createTime', 'signingDate', 'contractCode', 'item', 'company', 'depositPark', 'parkNumber', 'ownerCode', 'ownerName', 'socialCreditcode', 'idNumber', 'contractor', 'contactAddress', 'contactMethod', 'projectCode', 'projectName', 'projectAddress', 'landNumber', 'landUserpermit', 'leasePurpose', 'leaseArea', 'rentStandard', 'totalRent', 'totalRentdetail', 'increaseRent', 'rentMethod', 'firstPayDate', 'marginAmount', 'deliverTime', 'leaseStarttime', 'leaseEndtime', 'contractArrange', 'contractFile', 'bpmStatus', 'isThreeSeven'))
    },
    handleChangeTotal(event) {
      const convertCurrency = this.$convertCurrency(event)// 报销总金额大写转换
      this.form.setFieldsValue({ totalRentdetail: convertCurrency })
    },
    validateDate(type, value, row, column, callback, target) {
      if (type === 'blur' || type === 'change') {
        const { values } = target.getValuesSync({ validate: false, rowIds: [row.id] })
        if (values.length <= 0) {
          callback()
          return
        }
        const start_date = this.getDateTime(values[0].startDate)
        const end_date = this.getDateTime(values[0].endDate)
        if (end_date && start_date && start_date >= end_date) {
          callback(false, '开始时间必须小于结束时间')
        }
        callback(true) // true = 通过验证
      } else {
        callback() // 不填写或者填写 null 代表不进行任何操作
      }
    },
    validateCollectionDate(type, value, row, column, callback, target) {
      if (type === 'blur' || type === 'change') {
        const { values } = target.getValuesSync({ validate: false, rowIds: [row.id] })
        if (values.length <= 0) {
          callback()
          return
        }
        const collectionDate = this.getDateTime(values[0].collectionDate)
        const end_date = this.getDateTime(values[0].endDate)
        if (end_date && collectionDate && collectionDate >= end_date) {
          callback(false, '应收日期必须小于账单结束时间')
        }
        callback(true) // true = 通过验证
      } else {
        callback() // 不填写或者填写 null 代表不进行任何操作
      }
    },
    validateHouseCode(type, value, row, column, callback, target) {
      if (type === 'blur' || type === 'change') {
        const { values } = target.getValuesSync({ validate: false, rowIds: [row.id] })
        if (values.length <= 0) {
          callback()
          return
        }
        const house_code = values[0].houseCode
        let flag
        const { values: values1 } = target.getValuesSync({ validate: false })
        values1.forEach(item => {
          console.log(item)
          if (item.id !== row.id && item.houseCode === house_code) {
            flag = true
            return false
          }
        })
        if (flag) {
          callback(false, '房源不能重复')
        } else {
          callback(true) // true = 通过验证
        }
      } else {
        callback() // 不填写或者填写 null 代表不进行任何操作
      }
    },
    handleOk2() {
      const { values } = this.$refs[this.refKeys[1]].getValuesSync({ validate: false })
      if (values.length <= 0) {
        this.$message.warning('至少填写一行租赁合同款项信息')
        return false
      }
      this.handleOk()
    },
    houseCodeCallback(row, props) {
      if (row.houseCode) {
        const rows = []
        Object.keys(row).forEach(key => {
          const list = row[key] ? row[key].split(',') : []
          list.forEach((item, i) => {
            rows[i] ? '' : rows[i] = {}
            rows[i][key] = item
          })
        })
        const { values } = this.$refs[this.refKeys[0]].getValuesSync({ validate: false })
        const list = JSON.parse(JSON.stringify(values))
        list.forEach((item, i) => {
          if (item.id === props.rowId) {
            const currentRow = rows.shift()
            currentRow.id = props.rowId
            list[i] = currentRow
          }
        })
        if (rows.length > 0) {
          rows.forEach(item => {
            list.push(item)
          })
        }
        this.xyParkLeasecontractDetailTable.dataSource = list
        this.setServiceArea()
      } else { // 清空时，清空行数据
        props.target.setValues([{
          rowKey: props.rowId,
          values: { houseCode: '', buildingCode: '', buildingName: '', projectCode: '', projectName: '', floor: '', buildingArea: '', propertyArea: '', decoration: '', houseType: '' }
        }])
        this.setServiceArea()
      }
    },
    setServiceArea() { // 汇总主表租赁面积
      setTimeout(() => {
        const { values } = this.$refs[this.refKeys[0]].getValuesSync({ validate: false })
        let leaseArea = 0
        values.forEach((item, i) => {
          leaseArea += Number(item.buildingArea)
        })
        this.form.setFieldsValue({ leaseArea: leaseArea })
      }, 100)
    },
    getDateTime(date) {
      let date_ = date
      if (date_) {
        date_ = this.dateFtt('yyyy-MM-dd', new Date(date_))
      }
      return date_ && new Date(date_).getTime()
    },
    dateFtt(fmt, date) { // author: meizz
      var o = {
        'M+': date.getMonth() + 1, // 月份
        'd+': date.getDate(), // 日
        'h+': date.getHours(), // 小时
        'm+': date.getMinutes(), // 分
        's+': date.getSeconds(), // 秒
        'q+': Math.floor((date.getMonth() + 3) / 3), // 季度
        'S': date.getMilliseconds() // 毫秒
      }
      if (/(y+)/.test(fmt)) { fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length)) }
      for (var k in o) {
        if (new RegExp('(' + k + ')').test(fmt)) { fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length))) }
      }
      return fmt
    }

  }
}
</script>

<style scoped>
</style>
